package com.learning.spring.aop.aspectj.annotation.base;

import com.learning.spring.aop.aspectj.AopService;
import com.learning.spring.aop.aspectj.AopServiceImpl;
import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * ClassName: AspectConfig
 * Description: JavaConfig 配置
 * Date: 2019/4/26 13:52 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Configuration
@EnableAspectJAutoProxy
public class AspectConfig {

    /**
     * 目标
     *
     * @return
     */
    @Bean
    public AopService aopServiceTarget() {
        return new AopServiceImpl();
    }


    /**
     * 切面类
     *
     * @return
     */
    @Bean
    public AopAnnotationAspect preGreetingAspect() {
        return new AopAnnotationAspect();
    }

    /**
     * 配置自动创建代理器
     * AnnotationAwareAspectJAutoProxyCreator 自动将 AspectJ 注解切面织入目标Bean中，创建代理
     *
     * EnableAspectJAutoProxy 注解对应 <aop:aspectj-autoproxy/> 标签，注解内部使用的也是 AnnotationAwareAspectJAutoProxyCreator 这个类。
     *
     * @return
     */
    @Bean
    public AnnotationAwareAspectJAutoProxyCreator creator() {
        return new AnnotationAwareAspectJAutoProxyCreator();
    }
}
